let nowPassword = null,
    newPassword = null,
    nextPassword = null

let initPassword = () => {
    listenerNowPwd()
    listenerNewPwd()
    listenerNextPwd()
    listenerSave()
}

let listenerNowPwd = () => {
    $('.pwd-list-right-input')[0].addEventListener('change',(e)=>{
        nowPassword = e.target.value.replaceAll(' ','')
    })
}

let listenerNewPwd = () => {
    $('.pwd-list-right-input')[1].addEventListener('change',(e)=>{
        newPassword = e.target.value.replaceAll(' ','')
    })
}

let listenerNextPwd = () => {
    $('.pwd-list-right-input')[2].addEventListener('change',(e)=>{
        nextPassword = e.target.value.replaceAll(' ','')
    })
}

let listenerSave = () => {
    $('.pwd-save')[0].addEventListener('click',async (e) => {
        if(nowPassword === ''){
            Dreamer.warning("请输入旧密码", 2000);
            return
        }
        if(newPassword === ''){
            Dreamer.warning("请输入旧密码", 2000);
            return
        }
        if(nextPassword === ''){
            Dreamer.warning("请输入旧密码", 2000);
            return
        }
        if(newPassword !== nextPassword){
            Dreamer.warning("两次密码不一样", 2000);
            return
        }
        let res = await ajax('student_password_update1',{
            password : nowPassword,
            password1 : newPassword
        },'post')
        if(res.code === 200){
            Dreamer.success("修改成功", 2000);
        }else{
            Dreamer.error("修改失败", 2000);
        }
        console.log(res)
    })
}

export default initPassword